﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.CampaignSystem.MapNotificationTypes.MarriageOfferMapNotification
// Assembly: TaleWorlds.CampaignSystem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E85F8C15-4DF6-4E9C-A58A-29177E40D07A
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\bin\Win64_Shipping_Client\TaleWorlds.CampaignSystem.dll

using System.Collections.Generic;
using TaleWorlds.CampaignSystem.CampaignBehaviors;
using TaleWorlds.Core;
using TaleWorlds.Library;
using TaleWorlds.Localization;
using TaleWorlds.SaveSystem;

#nullable disable
namespace TaleWorlds.CampaignSystem.MapNotificationTypes
{
  public class MarriageOfferMapNotification : InformationData
  {
    internal static void AutoGeneratedStaticCollectObjectsMarriageOfferMapNotification(
      object o,
      List<object> collectedObjects)
    {
      ((InformationData) o).AutoGeneratedInstanceCollectObjects(collectedObjects);
    }

    protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
    {
      base.AutoGeneratedInstanceCollectObjects(collectedObjects);
      collectedObjects.Add((object) this.Suitor);
      collectedObjects.Add((object) this.Maiden);
    }

    internal static object AutoGeneratedGetMemberValueSuitor(object o)
    {
      return (object) ((MarriageOfferMapNotification) o).Suitor;
    }

    internal static object AutoGeneratedGetMemberValueMaiden(object o)
    {
      return (object) ((MarriageOfferMapNotification) o).Maiden;
    }

    public override TextObject TitleText => new TextObject("{=1OQubYTT}Marriage Offer");

    public override string SoundEventPath => "event:/ui/notification/marriage";

    [SaveableProperty(1)]
    public Hero Suitor { get; private set; }

    [SaveableProperty(2)]
    public Hero Maiden { get; private set; }

    public MarriageOfferMapNotification(
      Hero firstHero,
      Hero secondHero,
      TextObject descriptionText)
      : base(descriptionText)
    {
      this.Suitor = firstHero.IsFemale ? secondHero : firstHero;
      this.Maiden = firstHero.IsFemale ? firstHero : secondHero;
    }

    public override bool IsValid()
    {
      bool flag = Campaign.Current.Models.MarriageModel.IsCoupleSuitableForMarriage(this.Suitor, this.Maiden);
      if (flag && MBSaveLoad.IsUpdatingGameVersion && MBSaveLoad.LastLoadedGameVersion < ApplicationVersion.FromString("v1.2.0"))
      {
        MarriageOfferCampaignBehavior behavior = Campaign.Current.CampaignBehaviorManager.GetBehavior<MarriageOfferCampaignBehavior>();
        flag = behavior != null && behavior.IsThereActiveMarriageOffer;
      }
      if (!flag)
        CampaignEventDispatcher.Instance.OnMarriageOfferCanceled(this.Suitor, this.Maiden);
      return flag;
    }
  }
}
